package com.larissa.android.quiz.question;

import android.content.Context;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;

public class QuestionRepository {
    private static QuestionRepository repository;
    private List<Question> geoQuestions;
    private List<Question> mathQuestions;
    private List<Question> questionsToBeUpdated;
    private List<Question> questionsToBeInserted;
    private List<Question> questionsToBeDeleted;
    private Context context;


    private QuestionRepository(Context context) {
        mathQuestions = new ArrayList<>();
        geoQuestions = new ArrayList<>();
        questionsToBeUpdated = new LinkedList<>();
        questionsToBeInserted = new LinkedList<>();
        questionsToBeDeleted = new LinkedList<>();
        this.context = context;
    }

    public static void init(Context context) {
        if (repository == null)
            repository = new QuestionRepository(context);
    }

    public static QuestionRepository getInstance() {
        if (repository == null)
            throw new IllegalStateException("QuestionRepository must be initialized!");
        return repository;
    }

    public List<Question> getGeoQuestions() {
        return geoQuestions;
    }

    public List<Question> getMathQuestions() {
        return mathQuestions;
    }

    public List<Question> getQuestionsToBeUpdated() {
        return questionsToBeUpdated;
    }

    public List<Question> getQuestionsToBeInserted() {
        return questionsToBeInserted;
    }

    public List<Question> getQuestionsToBeDeleted() {
        return questionsToBeDeleted;
    }

    public void readQuestionsFromDB() {
        SqliteHelper helper = new SqliteHelper(context);
        helper.query();
    }


    public void saveQuestionsToDB() {
        SqliteHelper helper = new SqliteHelper(context);
        helper.update();
        helper.insert();
        helper.delete();
    }


}
